<template>
	<view>
		<view class="top-date-view">
			<view class="circle-date" @click="leftClick">
				<u-icon name="arrow-left" color="#ffffff"></u-icon>
			</view>
			<text class="title" @click="dateClick">
				{{$u.timeFormat(timestamp, 'yyyy-mm-dd')}}
			</text>
			<view class="circle-date" @click="rightClick">
				<u-icon name="arrow-right" color="#ffffff"></u-icon>
			</view>
		</view>
		
		<u-table v-if="list.length > 0">
			<u-tr class="tr-top">
				<u-td>检查对象</u-td>
				<u-td>
					<view>
						检查数/项目数
					</view>
					<view>
						检查得分/总分
					</view>
					<view>
						得分率
					</view>
				</u-td>
				<u-td>检查人/时间</u-td>
			</u-tr>

			<view v-for="(item, index) in list" :key="index"  @click="itemClick(item)">
				<u-tr class="tr">
					<u-td>{{item.targetClass}}</u-td>
					<u-td>
						<view>
							{{item.recordNumber}} / {{item.projectNumber}}
						</view>
						<view>
							{{item.recordCount}} / {{item.projectCount}}
						</view>
						<view>
							{{item.percentage}}
						</view>
					</u-td>
					<u-td>{{item.userName}}</u-td>
				</u-tr>
			</view>

		</u-table>
		
		<u-empty class="noContent" v-if="list.length === 0" text="暂时没有数据哦～"  mode="list"></u-empty>
		
		<u-picker v-model="timeShow" mode="time" :params="params" @confirm="confirmTime"></u-picker>
	</view>
</template>

<script>
	import { getTargetCensus } from '@/api/xj.js'
	import {
		formatDateByTimestamp
	} from '@/utils/utils.js'
	export default {
		data() {
			return {
				list: [],
				
				timeShow: false,

				timestamp: 0,
				params: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false,
					timestamp: true,
				},
			}
		},
		onLoad(options) {
			console.log(options);
			this.targetId = options.targetId;
			uni.setNavigationBarTitle({
				title: options.name
			})
			this.timestamp = Date.now();
			this.getList();
		},
		methods: {
			getList() {
				const dateStr = formatDateByTimestamp(this.timestamp, 'yyyy-mm-dd');
				const params = {
					targetId: this.targetId,
					time: dateStr
				}
				getTargetCensus(params).then(res => {
					console.log(res);
					this.list = res.data;
				})
			},
			
			leftClick() {
				let date = new Date(this.timestamp)
				const timestamp = date.setDate(date.getDate() - 1)
				this.confirmTime({timestamp: timestamp})
			},
			
			rightClick() {
				let date = new Date(this.timestamp)
				const timestamp = date.setDate(date.getDate() + 1)
				this.confirmTime({timestamp: timestamp})
			},
			
			dateClick() {
				this.timeShow = true;
			},
			
			confirmTime(res) {
				this.timestamp = res.timestamp
				this.getList();
			},
			
			itemClick(item) {
				console.log(item);
				this.$u.route({
					url: '/pages_operate/xj/xj-check-detail-page',
					params: item
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: $app-page-bg-color;
	}
	.tr-top{
		height: 200rpx;
		background-color: #f3f5f7;
	}
	.tr{
		height: 120rpx;
	}
	
	.top-date-view{
		padding: 20rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		
		.circle-date{
			width: 40rpx;
			height: 40rpx;
			background-color: $app-check-color;
			border-radius: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
		
		.title{
			margin-left: 30rpx;
			margin-right: 30rpx;
			font-size: $app-font-size-lg;
		}
	}
</style>
